package com.redoor.app.stake.basicdata.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.redoor.app.stake.basicdata.model.BaseFeeModelRel;
import com.redoor.app.stake.basicdata.model.controllerModel.BaseChargerfeemodelInfoCriteria;
import com.redoor.app.stake.basicdata.service.BaseFeeModelRelService;
import com.redoornetwork.framework.core.response.ResponseResult;
import com.redoornetwork.framework.core.response.ResultGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* Created by wangjunlei on 2018-03-14 10:38:41.
*/
@RestController
@RequestMapping("/base/chargerfeemodel/infos")
public class BaseChargerfeemodelInfoController {

    @Autowired
    private BaseFeeModelRelService baseFeeModelRelService;

    @PostMapping
    public ResponseResult add(@RequestBody BaseFeeModelRel baseFeeModelRel) {
        baseFeeModelRelService.save(baseFeeModelRel);
        return ResultGenerator.generatorSuccess();
    }

    @DeleteMapping("/{id}")
    public ResponseResult delete(@PathVariable String id) {
        baseFeeModelRelService.deleteById(id);
        return ResultGenerator.generatorSuccess();
    }

    @PutMapping
    public ResponseResult update(@RequestBody BaseFeeModelRel baseFeeModelRel) {
        baseFeeModelRelService.updateBySelective(baseFeeModelRel);
        return ResultGenerator.generatorSuccess();
    }

    @GetMapping("/{id}")
    public ResponseResult detail(@PathVariable String id) {
        BaseFeeModelRel baseFeeModelRel = baseFeeModelRelService.findById(id);
        return ResultGenerator.generatorSuccess(baseFeeModelRel);
    }

    @GetMapping
    public ResponseResult list(BaseChargerfeemodelInfoCriteria criteria) {
        PageHelper.startPage(criteria.getPageNum(), criteria.getPageSize());
        List<BaseFeeModelRel> list = baseFeeModelRelService.findAll();
        PageInfo pageInfo = new PageInfo(list);
        return ResultGenerator.generatorSuccess(pageInfo);
    }

}
